// 04-radio.js
const EventEmitter = require('events');

const Radio = function(station) {
  this.station = station;
}

Object.assign(Radio.prototype, EventEmitter.prototype);

//play 方法
Radio.prototype.play = function() {
  console.log(`Playing:${this.station.freq}`);
  setTimeout(() => {
    this.emit('play', this.station);
  }, 0);
};

//stop 方法
Radio.prototype.stop = function() {
  console.log(`Stopping:${this.station.name}`);
  setTimeout(() => {
    //stop事件，传递this.station作为参数
    this.emit('stop', this.station);
  }, 5000);
};

module.exports = Radio;